import torch
import torchvision
from PIL import Image
from torch import nn


image_path = "airplane.jpg"
image = Image.open(image_path)
print(image)
transform = torchvision.transforms.Compose([torchvision.transforms.Resize((32, 32)), torchvision.transforms.ToTensor()])
image = transform(image)
print(image.shape)
image = image.cuda()


class Wangqi(nn.Module):
    def __init__(self):
        super(Wangqi, self).__init__()
        self.modle1 = nn.Sequential(
            nn.Conv2d(3, 32, 5, padding=2),
            nn.MaxPool2d(2),
            nn.Conv2d(32, 32, 5, padding=2),
            nn.MaxPool2d(2),
            nn.Conv2d(32, 64, 5, padding=2),
            nn.MaxPool2d(2),
            nn.Flatten(),
            nn.Linear(1024, 64),
            nn.Linear(64, 10)
        )

    def forward(self, x):
        x = self.modle1(x)
        return x


model = torch.load("Wangqi_2.pth")
image = torch.reshape(image, (1, 3, 32, 32))
model=model.cuda()
model.eval()
with torch.no_grad():
    output = model(image)
print(output)
# print(output.argmax(1).item())
target=output.argmax(1).item()
print(target)


train_data = torchvision.datasets.CIFAR10("../CIFAR10_dataset", train=True, transform=torchvision.transforms.ToTensor(),
                                          download=True)
print(train_data.classes)
print(train_data.classes[target])